/* Copyright (c) 2025 Beijing Semidrive Technology Corporation
 * SPDX-License-Identifier: Apache-2.0
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/** *****************************************************************************************************
 * \file     Mcu_Reset.c                                                                                *
 * \brief    AUTOSAR 4.3.1 MCAL Mcu Driver                                                              *
 *                                                                                                      *
 * <table>                                                                                              *
 * <tr><th>Date           <th>Version                                                                   *
 * <tr><td>2023/08/02     <td>1.0.0                                                                     *
 * </table>                                                                                             *
 *******************************************************************************************************/
/********************************************************************************************************
 *                                      Include header files                                            *
 *******************************************************************************************************/
#include "Mcu_GeneralTypes.h"
#include "Mcu_Reset.h"
#include "Mcu_ResetDrv.h"

#define MCU_START_SEC_CODE
#include "Mcu_MemMap.h"
/********************************************************************************************************
 *                                  Global Function Declarations                                        *
 *******************************************************************************************************/
/** *****************************************************************************************************
 * \brief Assert a reset signal.
 * The reset singal will stay asserted until Mcu_Ip_ResetCtlDeassert() is called.
 *
 * \verbatim
 * Syntax             : Std_ReturnType Mcu_Ip_ResetCtlAssert(const Mcu_ResetSigType *rstSigPtr)
 *
 * Service ID[hex]    : None
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : Non reentrant
 *
 * Parameters (in)    : rstSigPtr - Reset signal.
 *
 * Parameters (inout) : None
 *
 * Parameters (out)   : None
 *
 * Return value       : 0 if OK, or a error code.
 *
 * Description        : Assert a reset signal.
 *
 * \endverbatim
 * Traceability       : SW_SM006
 *******************************************************************************************************/
Std_ReturnType Mcu_Ip_ResetCtlAssert(const Mcu_ResetSigType *rstSigPtr)
{
    Std_ReturnType errStatus = MCU_E_PARAM_POINTER;

    if (NULL_PTR != rstSigPtr)
    {
        errStatus = Mcu_Ip_ResetDrvAssert(rstSigPtr->base, rstSigPtr->id);
    } /* else not needed */

    return errStatus;
}

/** *****************************************************************************************************
 * \brief Deassert a reset signal.
 *
 * \verbatim
 * Syntax             : Std_ReturnType Mcu_Ip_ResetCtlDeassert(const Mcu_ResetSigType *rstSigPtr)
 *
 * Service ID[hex]    : None
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : Non reentrant
 *
 * Parameters (in)    : rstSigPtr - Reset signal.
 *
 * Parameters (inout) : None
 *
 * Parameters (out)   : None
 *
 * Return value       : 0 if OK, or a error code.
 *
 * Description        : Deassert a reset signal.
 *
 * \endverbatim
 * Traceability       : SW_SM006
 *******************************************************************************************************/
Std_ReturnType Mcu_Ip_ResetCtlDeassert(const Mcu_ResetSigType *rstSigPtr)
{
    Std_ReturnType errStatus = MCU_E_PARAM_POINTER;

    if (NULL_PTR != rstSigPtr)
    {
        errStatus = Mcu_Ip_ResetDrvDeassert(rstSigPtr->base, rstSigPtr->id);
    } /* else not needed */

    return errStatus;
}

/** *****************************************************************************************************
 * \brief Assert a reset signal, and deassert automatically.
 *
 * \verbatim
 * Syntax             : Std_ReturnType Mcu_Ip_ResetCtlReset(const Mcu_ResetSigType *rstSigPtr)
 *
 * Service ID[hex]    : None
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : Non reentrant
 *
 * Parameters (in)    : rstSigPtr - Reset signal.
 *
 * Parameters (inout) : None
 *
 * Parameters (out)   : None
 *
 * Return value       : 0 if OK, or a error code.
 *
 * Description        : Assert a reset signal, and deassert automatically.
 *
 * \endverbatim
 * Traceability       : SW_SM006
 *******************************************************************************************************/
Std_ReturnType Mcu_Ip_ResetCtlReset(const Mcu_ResetSigType *rstSigPtr)
{
    Std_ReturnType errStatus = MCU_E_PARAM_POINTER;

    if (NULL_PTR != rstSigPtr)
    {
        errStatus = Mcu_Ip_ResetDrvReset(rstSigPtr->base, rstSigPtr->id);
    } /* else not needed */

    return errStatus;
}

/** *****************************************************************************************************
 * \brief Check reset signal status.
 *
 * \verbatim
 * Syntax             : uint32 Mcu_Ip_ResetCtlStatus(const Mcu_ResetSigType *rstSigPtr)
 *
 * Service ID[hex]    : None
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : Non reentrant
 *
 * Parameters (in)    : rstSigPtr - Reset signal.
 *
 * Parameters (inout) : None
 *
 * Parameters (out)   : None
 *
 * Return value       : 0 if deasserted, 1 if asserted,
 *                      or UINT32_MAX means error occured.
 *
 * Description        : Check reset signal status.
 *
 * \endverbatim
 * Traceability       : SW_SM006
 *******************************************************************************************************/
uint32 Mcu_Ip_ResetCtlStatus(const Mcu_ResetSigType *rstSigPtr)
{
    uint32 assertSatus = UINT32_MAX;

    if (NULL_PTR != rstSigPtr)
    {
        assertSatus = Mcu_Ip_ResetDrvStatus(rstSigPtr->base, rstSigPtr->id);
    } /* else not needed */

    return assertSatus;
}

/** *****************************************************************************************************
 * \brief Global reset.
 *
 * \verbatim
 * Syntax             : Std_ReturnType Mcu_Ip_ResetCtlGlobalReset(const Mcu_ResetSigType *rstGlbCtlPtr)
 *
 * Service ID[hex]    : None
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : Non reentrant
 *
 * Parameters (in)    : rstGlbCtlPrt - Global reset controller.
 *
 * Parameters (inout) : None
 *
 * Parameters (out)   : None
 *
 * Return value       : errID
 *
 * Description        : Global reset.
 *
 * \endverbatim
 * Traceability       : SW_SM006
 *******************************************************************************************************/
Std_ReturnType Mcu_Ip_ResetCtlGlobalReset(const Mcu_ResetSigType *rstGlbCtlPtr)
{
    Std_ReturnType errStatus = MCU_E_PARAM_POINTER;

    if (NULL_PTR != rstGlbCtlPtr)
    {
        Mcu_Ip_ResetDrvGlobalReset(rstGlbCtlPtr->base);
        errStatus = E_OK;
    } /* else not needed */

    return errStatus;
}

#define MCU_STOP_SEC_CODE
#include "Mcu_MemMap.h"
/* End of file */
